function showModal(title, message, callback) {
    // Create modal elements
    const modal = document.createElement('div');
    modal.className = 'modal';

    const modalContent = document.createElement('div');
    modalContent.className = 'modal-content';

    const modalHeader = document.createElement('div');
    modalHeader.className = 'modal-header';

    const closeBtn = document.createElement('span');
    closeBtn.className = 'close-modal';
    closeBtn.innerHTML = '&times;';

    const titleElement = document.createElement('h2');
    titleElement.textContent = title;

    const modalBody = document.createElement('div');
    modalBody.className = 'modal-body';
    modalBody.textContent = message;

    const modalFooter = document.createElement('div');
    modalFooter.className = 'modal-footer';

    const confirmBtn = document.createElement('button');
    confirmBtn.className = 'btn btn-primary';
    confirmBtn.textContent = '确定';

    const cancelBtn = document.createElement('button');
    cancelBtn.className = 'btn btn-secondary';
    cancelBtn.textContent = '取消';
    cancelBtn.style.marginRight = '10px';

    // Construct modal
    modalHeader.appendChild(titleElement);
    modalHeader.appendChild(closeBtn);
    modalFooter.appendChild(cancelBtn);
    modalFooter.appendChild(confirmBtn);

    modalContent.appendChild(modalHeader);
    modalContent.appendChild(modalBody);
    modalContent.appendChild(modalFooter);

    modal.appendChild(modalContent);
    document.body.appendChild(modal);

    // Show modal
    modal.style.display = 'block';

    // Event handlers
    function closeModal() {
        modal.style.display = 'none';
        document.body.removeChild(modal);
    }

    closeBtn.onclick = closeModal;
    cancelBtn.onclick = closeModal;
    confirmBtn.onclick = function () {
        if (callback) {
            callback();
        }
        closeModal();
    };

    window.onclick = function (event) {
        if (event.target === modal) {
            closeModal();
        }
    };
}

// Helper function to replace alert
function showAlert(message) {
    showModal('提示', message);
}

// Helper function to replace confirm
function showConfirm(message, callback) {
    showModal('确认', message, callback);
}
